﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Data.SqlClient;
using System.Data;

using System.Configuration;

namespace Corsat.Library.DataManager
{
    public static partial class Main
    {

        public static List<Item> Search(SearchOptions SearchOption, string SearchKeyWord)
        {
            switch (SearchOption)
            {
                case SearchOptions.CorsatId:
                    command.CommandText = "SELECT AccountsMaster.AccountId ItemId, ArabicName ItemName FROM AccountsMaster inner join AccountsDetails on AccountsMaster.AccountId = AccountsDetails.AccountId WHERE AccountsDetails.CorsatId = " + SearchKeyWord;
                    break;

                case SearchOptions.Name:
                    command.CommandText = "SELECT AccountId ItemId, ArabicName ItemName FROM AccountsMaster WHERE ArabicName LIKE N'%" + SearchKeyWord + "%'";
                    break;

                case SearchOptions.SocialSecurityNumber:
                    command.CommandText = "SELECT AccountId ItemId, ArabicName ItemName FROM AccountsMaster WHERE SSN = '" + SearchKeyWord + "'";
                    break;

                default:
                    command.CommandText = "SELECT AccountId ItemId, ArabicName ItemName FROM AccountsMaster";
                    break;
            }
          
            if (command.CommandText != "")
                command.CommandText += " ORDER BY ArabicName asc";

            command.CommandType = CommandType.Text;

            DataTable dtMaster = new DataTable();

            adapter.Fill(dtMaster);


            List<Item> Items = ConvertTableToSmallItems(dtMaster);

            return Items;
        }

    }
}
